package com.ftdigital.primemovers_operators;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

import com.bugtags.library.Bugtags;
import com.bugtags.library.BugtagsOptions;
import com.ftdigital.primemovers_operators.config.GlobalData;
import com.ftdigital.primemovers_operators.model.UserInfo;

/**
 * Created by Curry on 2015-12-30.
 */
public class MyApplication extends Application {
    public static MyApplication myApplication;
    private static String LAST_REFRESH_TIME = "last_refresh_time.pref";
    public static UserInfo userInfo;
    @Override
    public void onCreate() {
        super.onCreate();
        myApplication = this;
        initView();

    }

    private void initView() {
        BugtagsOptions options = new BugtagsOptions.Builder().
                trackingLocation(true).//是否获取位置
                trackingCrashLog(true).//是否收集crash
                trackingConsoleLog(true).//是否收集console log
                trackingUserSteps(true).//是否收集用户操作步骤
                crashWithScreenshot(true).//crash附带图
                build();
        //在这里初始化
        Bugtags.start("332b206ae8191e0cd326a2129cb2d031", this, Bugtags.BTGInvocationEventBubble);
    }

    //获取实例
    public static Application getInstance() {
        return myApplication;
    }

    public static void pushRefreashTime(String key,long value) {
        SharedPreferences sharedPreferences = myApplication.getSharedPreferences(LAST_REFRESH_TIME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putLong(key, value);
        editor.commit();
    }

    public static long getRefreashTime(String key) {
        SharedPreferences sharedPreferences = myApplication.getSharedPreferences(LAST_REFRESH_TIME, Context.MODE_PRIVATE);
        return sharedPreferences.getLong(key, 0);
    }
}
